package com.yyh;

import java.util.Arrays;
import java.util.Comparator;

public class TestBook {
    public static void main(String[] args) {
        // 创建Book数组并初始化
        Book[] books = {
                new Book(1,"Java编程思想", "张三", 88,100, 500),
                new Book(2,"Effective Java", "李四", 89.0,200, 800),
                new Book(3,"Head First设计模式", "王五", 78.0,10, 300),
                new Book(4,"Spring实战", "赵六", 65.0,180, 600),
                new Book(5,"Spring实战", "钱七", 65.0,0, 600),
        };

        System.out.println("排序前：");
        System.out.println("编号\t书名\t\t作者\t价格\t销量\t库存\t图片");
        for (int i = 0; i < books.length; i++) {
            System.out.println(books[i].getInfo());
        }

        //排序： 从大到小
        for (int i = 1; i < books.length; i++) {
            for (int j = 0; j < books.length-i; j++) {
                if(books[j].getSales() < books[j+1].getSales()){
                    Book temp = books[j];
                    books[j] = books[j+1];
                    books[j+1] = temp;
                }
            }
        }
        System.out.println("排序后：");
        System.out.println("编号\t书名\t\t作者\t价格\t销量\t库存\t图片");
        for (int i = 0; i < books.length; i++) {
            System.out.println(books[i].getInfo());
        }
    }
}
